package com.itheima.mall.controller.smsController;

import com.itheima.mall.commons.R;
import com.itheima.mall.service.smsService.SmsFlashPromotionSessionService;
import com.itheima.pojo.sms.SmsFlashPromotionSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/flashSession")
public class SmsFlashPromotionSessionController {
    @Autowired
    private SmsFlashPromotionSessionService smsFlashPromotionSessionService;
    /**
     * 添加场次
     */
    @PostMapping("create")
    public R create(@RequestBody SmsFlashPromotionSession smsFlashPromotionSession) {
        return smsFlashPromotionSessionService.create(smsFlashPromotionSession);
    }

    /**
     * 删除场次
     */
    @PostMapping("/delete/{id}")
    public R delete(@PathVariable Long id) {
        return smsFlashPromotionSessionService.delete(id);
    }

    /**
     * 获取全部场次
     */
    @GetMapping("list")
    public R list() {
        return smsFlashPromotionSessionService.list();
    }

    /**
     * 获取全部可选场次及其数量
     */
    @GetMapping("selectList")
    public R selectList(@RequestParam(value = "flashPromotionId")Long flashPromotionId) {
        return smsFlashPromotionSessionService.selectList(flashPromotionId);
    }

    /**
     * 修改启用状态
     */
    @PostMapping("update/status/{id}")
    public R updateStatus(@RequestBody Map<Long,Long> map) {
        return smsFlashPromotionSessionService.updateStatus(map);
    }

    /**
     * 修改场次
     */
    @PostMapping("update/{id}")
    public R update(@PathVariable Long id,@RequestBody SmsFlashPromotionSession smsFlashPromotionSession) {
        return smsFlashPromotionSessionService.update(id,smsFlashPromotionSession);
    }

    /**
     * 获取场次详情
     *
     */
    @GetMapping("{id}")
    public R getFlashSession(@PathVariable Long id){
        return smsFlashPromotionSessionService.getFlashSession(id);
    }

}
